package btime.logic;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * The Time Container
 * Ideas:
 * We want a Graphical representation of Binary Time.
 * Therefor we need Container of elements {0,1}, 
 * that can easily be identified and replaced with Graphical elements.
 * ? What should that Container be: String of 0,1 ; List of boolean/integer {0,1} ; Generic List ? 
 * @author Jordan
 */
public class Time {
	String sTime, hours, mins, secs;	// String representation of Decimal Time HH:MM:SS  12:32:35
	String sbHours, sbMins, sbSecs; 		// Binary Strings in the Form XX example 01 = 1 ; 11 = 
	
        // List of boolean to display
        boolean[][] bTime = new boolean[3][6];
//        boolean[] basbSecs = new boolean[6]; // Array of Booleans
        
	public Time () {
		refreshTime();
	}
/*
 * getMethods that bring us the Binary representation of HH MM SS in a String
 * We need to add '0' infront so the number of signs is = 6 ; XXXXXX X={0,1}
 */	
	public String getHours(){
		return sbHours;
	}
	public String getMins(){
		return sbMins;
	}
	public String getSecs(){
		return sbSecs;
	}

	
	/**
         * Writes the current TIME in the Variables of Time CLASS,
         * Both String and Binary representations.
         * At the end we got all Strings that represent the TIME in binary.
         * sbHours, sbMins, sbSecs
         */
	public void refreshTime() {
//		write_sTime();
                sTime = getDateTime();
		split_sTime();
		//String binaryString = Integer.toBinaryString(/*int*/number);
		sbHours = Integer.toBinaryString( Integer.parseInt(hours) );	
		sbMins = Integer.toBinaryString( Integer.parseInt(mins) );
		sbSecs = Integer.toBinaryString( Integer.parseInt(secs) );
                
                //use matrix 
                boolean bTemp = false;
                String str = "000000";
                for (int i = 0; i < bTime.length ; i++){
                    switch (i){
                        case 0:
                            str = sbHours;
                            break;
                        case 1:
                            str = sbMins;
                            break;
                        case 2:
                            str = sbSecs;
                            break;
                    }
                    // str = 0-6 char String
                    int emptyOs = 6 - str.length(); // if number 11 =  000011 => 4 empty
                    for (int j = 0; j < bTime[i].length ; j++){
                        if (emptyOs <= j && emptyOs != 0){
                            // add a 0
                        }
                        
//                        bTime[i][j] = bTemp;
                    }
                }
	}
	
        /**
         * Writes time HH:mm:ss in to sTime :String representation
         */
//	public void write_sTime () {
//		sTime = getDateTime();
//	}
	/**
         * Splits the String Representation of Time in hours, minutes and seconds.
         */
	public void split_sTime (){
		String[] timeStringArray = splitTimeStringSplitElement(sTime);
		hours = timeStringArray[0];
		mins = timeStringArray[1];
		secs = timeStringArray[2];
	}
	
	private String[] splitTimeStringSplitElement (String s) {
		return s.split(":");
	}

	/**
	 * Gets the actual time / date and time, as a String Now it returns Hours:Minutes:Seconds
	 * @return
	 */
	public String getDateTime() {
	    //DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
	    Date date = new Date();
	    return dateFormat.format(date);
	}
	
}